package com.maegul.web.pages;

import org.apache.wicket.markup.html.form.RequiredTextField;
import org.apache.wicket.markup.html.form.StatelessForm;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.validation.validator.CreditCardValidator;

import com.maegul.web.MaegulSession;
import com.maegul.web.components.CheckOutCart;
import com.maegul.web.models.POJO.Cart;
import com.maegul.web.models.POJO.CreditCardInfo;
import com.maegul.web.pages.base.BasePage;

public class CreditCardCheckOut extends BasePage {

	private static final long serialVersionUID = 1L;

	protected CreditCardCheckOut() {
		super(CHECK_OUT_HEADER, CHECK_OUT_HEADER);
		add(new CreditCardForm("form_credit"));

		Cart cart = new Cart();
		cart.setCart(MaegulSession.get().getCart());

		add(new CheckOutCart("shoppingcart", cart));

	}

	private static class CreditCardForm extends StatelessForm<CreditCardInfo> {

		private static final long serialVersionUID = 1L;

		public CreditCardForm(String id) {
			super(id);

			CreditCardInfo info = new CreditCardInfo();
			setModel(new CompoundPropertyModel<CreditCardInfo>(info));

			add(new RequiredTextField<String>("name"));
			add(new RequiredTextField<String>("Street"));
			add(new RequiredTextField<Integer>("zipcode"));
			add(new RequiredTextField<String>("city"));
			add(new RequiredTextField<String>("country"));
			add(new RequiredTextField<Integer>("card_num")
					.add(new CreditCardValidator(true)));
			add(new RequiredTextField<Integer>("month"));
			add(new RequiredTextField<Integer>("year"));
		}

		@Override
		protected void onSubmit() {
			// TODO
		}

	}
}
